﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Diagnostics;

namespace HgRemoteContracts
{
	[DataContract]
	[DebuggerDisplay("{Status} {Path}")]
	public class StatusItem
	{
		[DataMember]
		public FileStatus Status { get; private set; }
		[DataMember]
		public string Path { get; private set; }

		private StatusItem()
		{
		}

		public static StatusItem Read(string line)
		{
			StatusItem s = new StatusItem();
			s.Status = FromStatusChar(line[0]);
			s.Path = line.Substring(2);
			return s;
		}

		public static FileStatus FromStatusChar(char ch)
		{
			switch(ch)
			{
				case 'M': return FileStatus.Modified;
				case 'A': return FileStatus.Added;
				case 'R': return FileStatus.Removed;
				case 'C': return FileStatus.Clean;
				case '!': return FileStatus.Missing;
				case '?': return FileStatus.Unknown;
				case 'I': return FileStatus.Ignored;
				default: return FileStatus.Invalid;
			}
		}
	}

	public enum FileStatus
	{
		Invalid,
		Modified,
		Added,
		Removed,
		Clean,
		Missing,
		Unknown,
		Ignored
	}
}